/**
 * 
 */
package co.fitstart.payment.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericJdbcSupport;

import co.fitstart.payment.entity.app.App;
import co.fitstart.payment.service.AppService;

/**
 * @author lute
 *
 */
@Service("appService")
public class AppServiceImpl implements AppService {

    @Autowired
    private GenericJdbcSupport genericJdbcSupport;

    /* (non-Javadoc)
     * @see co.fitstart.payment.service.AppService#load(java.lang.Long)
     */
    public App load(Long id) {
        String sentence = "SELECT id AS id, appid AS appid, appsecret AS appsecret, name AS name, alias AS alias, host AS host, is_disabled AS disabled FROM app WHERE id = :id";
        List<App> apps = genericJdbcSupport.queryForList(sentence, "id", id, App.class);
        return CollectionUtils.isEmpty(apps) ? null : apps.get(0);
    }

    /* (non-Javadoc)
     * @see cn.xcm.payment.service.AppService#getApp(java.lang.String)
     */
    public App getApp(String appid) {
        String sentence = "SELECT id AS id, appid AS appid, appsecret AS appsecret, name AS name, alias AS alias, host AS host, is_disabled AS disabled FROM app WHERE appid = :appid";
        List<App> result = genericJdbcSupport.queryForList(sentence, "appid", appid, App.class);
        return CollectionUtils.isNotEmpty(result) ? result.get(0) : null;
    }

}
